package com.dameng.work.service.impl;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dameng.work.mapper.GOODMapper;
import com.dameng.work.mapper.SHELLMapper;
import com.dameng.work.pojo.BRAND;
import com.dameng.work.pojo.GOOD;
import com.dameng.work.pojo.SHELL;
import com.dameng.work.service.GOODService;
import com.dameng.work.service.SHELLService;
import com.dameng.work.util.CustomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;


@Service
public class GOODServiceImpl implements GOODService {


    @Autowired
    private GOODMapper gOODMapper;


    @Override
    public List<GOOD> findAllList() {
        List<GOOD> tabnums = gOODMapper.selectList(new QueryWrapper<>());
        return tabnums;
    }

    @Override
    public void InsertGOOD(GOOD good1) throws IOException {

        for (int i = 0; i < 100000; i++) {
            GOOD good = new GOOD();
            good.setBRAND_ID(1);
            good.setBRAND_UUID("597059da5f214a538651a7aec378d111");
            good.setCATEGORY_ID(1);
            good.setSELLER_ID(1);
            good.setSELLER_UUID("2e96efd7dcd04bde9aea955eeddcbd71");


            String[] good_string = CustomUtil.readTargetFileNum(RandomUtil.randomInt(1, 20),"HW");
            if(i%500==0){
               good_string = CustomUtil.readTargetFileNum(RandomUtil.randomInt(1, 20),"HW");
            }
            good.setGOOD_ID(CustomUtil.getUUID());
            good.setNAME(i+good_string[2]);
            good.setPRICE(new BigDecimal(good_string[1]));
            good.setGOOD_DESC("这时商品介绍---"+i+"----"+good_string[2]);
            good.setIS_DELETE(0);
            gOODMapper.insert(good);
        }



    }

    @Override
    public void batchInsertGOOD_CUSTOM(BRAND bRAND, SHELL sHELL) throws IOException {

        ArrayList<GOOD> goodLists = new ArrayList<>();
        String[] good_string = null;
        Integer CATEGORY_ID = 1;
        for (int i = 0; i < 200; i++) {
            GOOD good = new GOOD();
            good.setBRAND_ID(bRAND.getID());
            good.setBRAND_UUID(bRAND.getBRAND_ID());
            good.setSELLER_ID(sHELL.getID());
            good.setSELLER_UUID(sHELL.getSHELL_ID());
            good_string = CustomUtil.readTargetFileNum(RandomUtil.randomInt(1, 15),StrUtil.trim(bRAND.getBRAND_JC()));
            if(i%200==0&&i!=0){
                good_string = CustomUtil.readTargetFileNum(RandomUtil.randomInt(1, 15),StrUtil.trim(bRAND.getBRAND_JC()));
                String CATEGORY_Str = good_string[0];
                if(CATEGORY_Str.equals("手机")){
                    CATEGORY_ID=1;
                }else if(CATEGORY_Str.equals("电脑")){
                    CATEGORY_ID=2;
                }
                gOODMapper.batchInsertList(goodLists);
                goodLists.clear();
            }
            //产品类型
            good.setCATEGORY_ID(RandomUtil.randomInt(1, 10));

            good.setGOOD_ID(CustomUtil.getUUID());
            good.setNAME(i+good_string[2]);
            good.setPRICE(new BigDecimal(good_string[1]));
            good.setGOOD_DESC("这时商品介绍---"+i+"----"+good_string[2]);
            good.setIS_DELETE(RandomUtil.randomInt(0, 1));
            goodLists.add(good);
        }

        gOODMapper.batchInsertList(goodLists);
    }


    @Override
    public void batchInsertGOOD(BRAND bRAND, SHELL sHELL) throws IOException {

        String[] good_string = null;
        Integer CATEGORY_ID = 1;
        for (int i = 0; i < 1000; i++) {
            GOOD good = new GOOD();
            good.setBRAND_ID(bRAND.getID());
            good.setBRAND_UUID(bRAND.getBRAND_ID());
            good.setSELLER_ID(sHELL.getID());
            good.setSELLER_UUID(sHELL.getSHELL_ID());

            if(i%500==0){
                good_string = CustomUtil.readTargetFileNum(RandomUtil.randomInt(1, 15),StrUtil.trim(bRAND.getBRAND_JC()));
            String CATEGORY_Str = good_string[0];
            if(CATEGORY_Str.equals("手机")){
                CATEGORY_ID=1;
            }else if(CATEGORY_Str.equals("电脑")){
                CATEGORY_ID=2;
            }
            }
            //产品类型
            good.setCATEGORY_ID(CATEGORY_ID);

            good.setGOOD_ID(CustomUtil.getUUID());
            good.setNAME(i+good_string[2]);
            good.setPRICE(new BigDecimal(good_string[1]));
            good.setGOOD_DESC("这时商品介绍---"+i+"----"+good_string[2]);
            good.setIS_DELETE(0);
            gOODMapper.insert(good);
        }

    }



    @Override
    public List<GOOD> queryGoodList() {

        List<GOOD> goods = gOODMapper.queryGoodList();
        return goods;
    }

    @Override
    public List<GOOD> queryGoodList1() {
        List<GOOD> goods = gOODMapper.queryGoodList1();
        return goods;
    }

}
